package com.gwcloud.leetcode.hot100;

/** 
* @ClassName   : Leetcode011 
* @author      : ganwei 
* @date        : 2020年5月4日 
* @Description : leetcode011 盛最多水的容器
*/
public class Leetcode0011 {
	/**
	 * -解题思路，纯暴力解决,O(N)LOG(N)
	 */
    public int maxArea(int[] height) {
    	int max = 0;
    	for(int j = 1; j < height.length; j++) {
    		for(int i = 0; i < j; i++) {
    			int tempArea = Math.min(height[i], height[j]) * (j-i);
    			max = Math.max(tempArea, max);
    		}
    	}
    	return max;
    }
    /**
     * -解题思路，双指针思路，算法复杂度O(N)
     */
    public int maxArea_1(int[] height) {
    	int max = 0;
    	int left = 0;
    	int right = height.length-1;
    	while(left < right) {
    		int tempArea = Math.min(height[left], height[right]) * (right-left);
    		max = Math.max(tempArea, max);
    		if(height[left] <= height[right]) {
    			left++;
    		}else {
    			right--;
    		}
    	}
    	return max;
    }
    
    public static void main(String[] args) {
    	Leetcode0011 l011 = new Leetcode0011();
    	int[] height = {1,8,6,2,5,4,8,3,7};
    	System.out.println(l011.maxArea_1(height));
    }
}
